package TableAdditions;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JPanel;
import javax.swing.JScrollPane;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

import Utility.BillLine;
import Utility.Customer;
import Utility.Product;
import Utility.Promotion;

public class FillBillDataAction {
	
	public static int duplicateCounter=0;
	public static int firstStartingPoint=0;
	public static BillLine fillBillPageData(BillLine billLine,String date,Product[] products,Promotion[] promotions,Customer[] customers,int duplicate){
		
		
		int recordCounter=0;
		int productIndex=0;
		duplicateCounter=0;
		
		
		//////System.out.println("in fill bill date !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
		
		////////////System.out.println("date of billLine="+date);
		//////////System.out.println("bill customer Code="+billLine.getCustomerCode());
		int customerIndex=-1;
		int promotionIndex=-1;
		
		Statement stmt = null;
    	Connection conn = null;
    	ResultSet rss = null;
    	String url = "jdbc:mysql://localhost:3306/mydb";
        String user = "root";
        String password = "qweasdzxc";
        
        
        try {
			conn = (Connection) DriverManager.getConnection(url, user, password);
			stmt = (Statement) conn.createStatement();
			
			
				
				recordCounter=0;
				customerIndex=-1;
				productIndex=-1;
			
				FillBillAction.billLines[billLine.getbillLineid()].getCreditCheckBox().setSelected(false);
				FillBillAction.billLines[billLine.getbillLineid()].getCashCheckBox().setSelected(false);
				FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().setText("");
				FillBillAction.billLines[billLine.getbillLineid()].setCashCheckBoxStatus(false);
				FillBillAction.billLines[billLine.getbillLineid()].setCreditCheckBoxStatus(false);
				FillBillAction.billLines[billLine.getbillLineid()].setCreditCashTextFieldStatus(false);
				
			
			rss=stmt.executeQuery("SELECT * from bill where customer_code='"+FillBillAction.billLines[billLine.getbillLineid()].getCustomerCode()+"' " +
					"and bill_date='"+date+"'");
			
			
			
			
			while(rss.next()){
				recordCounter++;
			}
			
			if(recordCounter>0){
			
				System.out.println("Record Counter= "+recordCounter+" Duplicate="+duplicate);
				rss.first();
				
				
				
				if(duplicate!=0){
					if(duplicate<=recordCounter && recordCounter>1){
						for(int i=0;i<recordCounter-1;i++){
							System.out.println("Record Skipped");
							rss.next();
						}
				}
				}
				
				
				
				
				
				
				//////System.out.println("satırı doldurdu:"+billLine.getBillId());
				
				
				
				for(int i=0;i<products.length;i++){
					////////////System.out.println("productId= "+products[i].getProductId()+" productId in bill= "+rss.getInt("product_id"));
					if(products[i].getProductId()==rss.getInt("product_id")){
						productIndex=i+1;
					}
				}
				
				
				
				FillBillAction.billLines[billLine.getbillLineid()].getBillProductComboBox().setSelectedIndex(productIndex);
				FillBillAction.billLines[billLine.getbillLineid()].setBillId(rss.getInt("bill_id"));
				FillBillAction.billLines[billLine.getbillLineid()].getAmountTextField().setText(rss.getString("bill_amount"));
				//billLines.getAmountTextField().setText("999");
				FillBillAction.billLines[billLine.getbillLineid()].getSumTextField().setText(rss.getString("bill_cost"));
				FillBillAction.billLines[billLine.getbillLineid()].setSpecialPrice(rss.getFloat("special_price"));
				FillBillAction.billLines[billLine.getbillLineid()].setProductId(rss.getInt("product_id"));
				FillBillAction.billLines[billLine.getbillLineid()].getPriceTextField().setText(
				Float.toString((FillBillAction.billLines[billLine.getbillLineid()].getSpecialPrice())));
				
				
					
					
					for(int n=0;n<customers.length;n++){
						////////////System.out.println("wanted cCode="+rss.getString("customer_code")+"   cCode= "+customers[n].getCustomerCode());
						if(rss.getString("customer_code").equals(customers[n].getCustomerCode())){
							customerIndex=n;
							//////////////System.out.println("customerName!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!="+customers[customerIndex].getCustomerName());
						}
					}
					
					// I find promtionIndex here
					
					for(int n=0;n<promotions.length;n++){
						
						////////System.out.println("wanted pId="+rss.getString("product_id")+"   pid= "+promotions[n].getPromotionProductId());
						////////System.out.println("wanted cId="+customers[customerIndex].getCustomerId()+"   pmCid= "+promotions[n].getPromotionCustomerId());
						if(rss.getInt("product_id")==promotions[n].getPromotionProductId() && customers[customerIndex].getCustomerId()==promotions[n].getPromotionCustomerId()){
							////////System.out.println("promotion found!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
							promotionIndex=n;
							////////System.out.println("promotion index="+promotionIndex);
						}
						
					}
					
					
					
					
					if(promotionIndex>-1){
						FillBillAction.billLines[billLine.getbillLineid()].getPromotionTextField().getDocument().removeDocumentListener(FillBillAction.promotionDocumentListener);
						FillBillAction.billLines[billLine.getbillLineid()].getPromotionTextField().setText(Integer.toString(rss.getInt("promotion_amount")));
						FillBillAction.billLines[billLine.getbillLineid()].setBillPromotionAmount(rss.getInt("promotion_amount"));
						FillBillAction.billLines[billLine.getbillLineid()].setBillModifyingPromotionAmount(0);
						FillBillAction.billLines[billLine.getbillLineid()].getPromotionTextField().getDocument().addDocumentListener(FillBillAction.promotionDocumentListener);					
						FillBillAction.billLines[billLine.getbillLineid()].getTotalPromotionTextField().setText(Integer.toString(promotions[promotionIndex].getPromotionUnit()));
					/*	//////System.out.println("");
						//////System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
						//////System.out.println("");
						//////System.out.println("bill Promotion Unit="+Integer.toString(promotions[promotionIndex].getPromotionUnit()));
						//////System.out.println("");
						//////System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
						//////System.out.println("");*/
						FillBillAction.billLines[billLine.getbillLineid()].setBillPromotionUnit(promotions[promotionIndex].getPromotionUnit());
						FillBillAction.billLines[billLine.getbillLineid()].setBillModifyingPromotionUnit(promotions[promotionIndex].getPromotionUnit());
						//////////System.out.println("billineId="+billLine.getbillLineid());
					//FillBillAction.billLines[billLine.getbillLineid()].getPromotionTextField().getDocument().addDocumentListener(FillBillAction.promotionDocumentListener);
						FillBillAction.Calculate(FillBillAction.tempRowCounter);
					
					}
					
					
					FillBillAction.billLines[billLine.getbillLineid()].getCashCheckBox().setEnabled(true);
					FillBillAction.billLines[billLine.getbillLineid()].getCreditCheckBox().setEnabled(true);;
					FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().setEnabled(true);	
					
					
					
				
				//FillBillAction.billLines[billLine.getbillLineid()].getCashCheckBox().setSelected(true);
				
					FillBillAction.billLines[billLine.getbillLineid()].setBillTotalCost(rss.getFloat("bill_cost"));
				//////////System.out.println("totalCost="+FillBillAction.billLines[billLine.getbillLineid()].getBillTotalCost());
				
				if(rss.getFloat("bill_credit")==rss.getFloat("bill_cost")){
					
					//////System.out.println("payed by credit");
					
					FillBillAction.billLines[billLine.getbillLineid()].getCreditCheckBox().setSelected(true);
					FillBillAction.billLines[billLine.getbillLineid()].getCreditCheckBox().doClick();
					FillBillAction.billLines[billLine.getbillLineid()].getCreditCheckBox().setSelected(true);
					FillBillAction.billLines[billLine.getbillLineid()].setBillCredit(rss.getFloat("bill_credit"));
					FillBillAction.billLines[billLine.getbillLineid()].setPayedCash(0);
					//////////System.out.println("credit="+FillBillAction.billLines[billLine.getbillLineid()].getBillCredit());
					FillBillAction.billLines[billLine.getbillLineid()].setCreditCashTextFieldStatus(true);
					FillBillAction.billLines[billLine.getbillLineid()].setCashCheckBoxStatus(false);
					FillBillAction.billLines[billLine.getbillLineid()].setCreditCashTextFieldStatus(false);
					/*FillBillAction.billLines[billLine.getbillLineid()].getCreditCheckBox().setEnabled(true);
					FillBillAction.billLines[billLine.getbillLineid()].getCashCheckBox().setEnabled(false);
					FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().setEnabled(false);*/
				}
				else if(rss.getFloat("bill_cash")==rss.getFloat("bill_cost")){
					
					////////System.out.println("payed by cash");
					
					FillBillAction.billLines[billLine.getbillLineid()].getCashCheckBox().setSelected(true);
					FillBillAction.billLines[billLine.getbillLineid()].setBillCash(rss.getFloat("bill_cash"));
					FillBillAction.billLines[billLine.getbillLineid()].setPayedCash(rss.getFloat("bill_cash"));
					//////////System.out.println("cash="+FillBillAction.billLines[billLine.getbillLineid()].getBillCash());
					FillBillAction.billLines[billLine.getbillLineid()].setCreditCashTextFieldStatus(false);
					FillBillAction.billLines[billLine.getbillLineid()].setCashCheckBoxStatus(true);
					FillBillAction.billLines[billLine.getbillLineid()].setCreditCashTextFieldStatus(false);
					/*FillBillAction.billLines[billLine.getbillLineid()].getCashCheckBox().setEnabled(true);
					FillBillAction.billLines[billLine.getbillLineid()].getCreditCheckBox().setEnabled(false);
					FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().setEnabled(false);*/
				}
				else{
					//////System.out.println("payed by creditcash");
				
					if(rss.getFloat("bill_cash")!=rss.getFloat("bill_cost") && rss.getFloat("bill_credit")!=rss.getFloat("bill_cost") ){
						FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().setText(Float.toString(rss.getFloat("bill_cash")));
						
					}
					FillBillAction.billLines[billLine.getbillLineid()].setBillCredit(rss.getFloat("bill_credit"));
					//////////System.out.println("remain="+FillBillAction.billLines[billLine.getbillLineid()].getBillCredit());
					FillBillAction.billLines[billLine.getbillLineid()].setBillCash(rss.getFloat("bill_cash"));
					//////////System.out.println("credit="+FillBillAction.billLines[billLine.getbillLineid()].getBillCredit());
					FillBillAction.billLines[billLine.getbillLineid()].setPayedCash(rss.getFloat("bill_cash"));
					FillBillAction.billLines[billLine.getbillLineid()].setCreditCashTextFieldStatus(false);
					FillBillAction.billLines[billLine.getbillLineid()].setCashCheckBoxStatus(false);
					FillBillAction.billLines[billLine.getbillLineid()].setCreditCashTextFieldStatus(true);
					/*FillBillAction.billLines[billLine.getbillLineid()].getCashCheckBox().setEnabled(false);
					FillBillAction.billLines[billLine.getbillLineid()].getCreditCheckBox().setEnabled(false);
					FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().setEnabled(true);*/
				}
				
				/*FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().setEditable(false);
				FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().removeMouseListener(FillBillAction.CustomMouseListener);
				FillBillAction.billLines[billLine.getbillLineid()].getCashCheckBox().setEnabled(false);
				FillBillAction.billLines[billLine.getbillLineid()].getCreditCheckBox().setEnabled(false);*/
             	
				FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().setEditable(true);
             	//FillBillAction.billLines[FillBillAction.selectedRadioButton].getCreditCashTextField().addMouseListener(FillBillAction.CustomMouseListener);
				FillBillAction.billLines[billLine.getbillLineid()].getCashCheckBox().setEnabled(true);
				FillBillAction.billLines[billLine.getbillLineid()].getCreditCheckBox().setEnabled(true);
				
				
             	FillBillAction.CalculateTotalCostOfLine();
				// I find customerIndex here
				FillBillAction.Calculate(FillBillAction.tempRowCounter);
				
			}
			else if(recordCounter==0){
				FillBillAction.CalculateTotalCostOfLine();
				FillBillAction.Calculate(FillBillAction.tempRowCounter);
				//////////System.out.println("recordCounter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!="+recordCounter);
				FillBillAction.billLines[billLine.getbillLineid()].getBillProductComboBox().setSelectedIndex(0);
				/*FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().setEditable(false);
				FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().removeMouseListener(FillBillAction.CustomMouseListener);
				FillBillAction.billLines[billLine.getbillLineid()].getCashCheckBox().setEnabled(false);
				FillBillAction.billLines[billLine.getbillLineid()].getCreditCheckBox().setEnabled(false);
             	
				if(billLine.getbillLineid()!=FillBillAction.selectedRadioButton){
					FillBillAction.billLines[FillBillAction.selectedRadioButton].getCreditCashTextField().setEditable(true);
					FillBillAction.billLines[FillBillAction.selectedRadioButton].getCreditCashTextField().addMouseListener(FillBillAction.CustomMouseListener);
					FillBillAction.billLines[FillBillAction.selectedRadioButton].getCashCheckBox().setEnabled(true);
					FillBillAction.billLines[FillBillAction.selectedRadioButton].getCreditCheckBox().setEnabled(true);
				}*/
			}
			
			 conn.close();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
       
       
		
		return null;
		
		
		
	}
	
	
	
	
	public static BillLine fillBillSpecialPageData(BillLine[] billLine,String date,Product[] products,Promotion[] promotions,Customer[] customers,int howMany,int startingPoint,String customerCode){
		
		
		int recordCounter=0;
		int productIndex=0;
		duplicateCounter=0;
		firstStartingPoint=startingPoint;
		
		//System.out.println("in fill special bill date !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
		
		////////////System.out.println("date of billLine="+date);
		//////////System.out.println("bill customer Code="+billLine.getCustomerCode());
		int customerIndex=-1;
		int promotionIndex=-1;
		
		Statement stmt = null;
    	Connection conn = null;
    	ResultSet rss = null;
    	String url = "jdbc:mysql://localhost:3306/mydb";
        String user = "root";
        String password = "qweasdzxc";
        
        
        try {
			conn = (Connection) DriverManager.getConnection(url, user, password);
			stmt = (Statement) conn.createStatement();
			
			
				recordCounter=0;
				
				for(int g=startingPoint;g<howMany;g++){
			
				FillBillAction.billLines[g].getCreditCheckBox().setSelected(false);
				FillBillAction.billLines[g].getCashCheckBox().setSelected(false);
				FillBillAction.billLines[g].getCreditCashTextField().setText("");
				FillBillAction.billLines[g].setCashCheckBoxStatus(false);
				FillBillAction.billLines[g].setCreditCheckBoxStatus(false);
				FillBillAction.billLines[g].setCreditCashTextFieldStatus(false);
				
				}
				
			//System.out.println("customerCode= "+customerCode);
			
			rss=stmt.executeQuery("SELECT * from bill where customer_code='"+customerCode+"' " +
					"and bill_date='"+date+"'");
			
			while(rss.next()){
				recordCounter++;
			}
			
			
			//System.out.println("recordCounter= "+recordCounter);
			
			
			if(recordCounter>0){
				
				
				
				
				rss=stmt.executeQuery("SELECT * from bill where customer_code='"+customerCode+"' " +
						"and bill_date='"+date+"'");
				
				
				
			int counter=0;
				
				
				
			while(rss.next() && counter<howMany && counter<recordCounter){
				
				//System.out.println(counter+". kayıt girildi!!!!!!!");
				
				customerIndex=-1;
				productIndex=-1;
				promotionIndex=-1;
				
				
				
				for(int i=0;i<products.length;i++){
					////////////System.out.println("productId= "+products[i].getProductId()+" productId in bill= "+rss.getInt("product_id"));
					if(products[i].getProductId()==rss.getInt("product_id")){
						productIndex=i+1;
					}
				}
				
				//System.out.println("productIndex="+productIndex);
				
				FillBillAction.billLines[startingPoint].getBillProductComboBox().setSelectedIndex(productIndex);
				//System.out.println("bill_id= "+rss.getInt("bill_id")+" product_id= "+rss.getInt("product_id")+" adet= "+rss.getString("bill_amount")+" özel fiyat= "+rss.getFloat("special_price"));
				FillBillAction.billLines[startingPoint].setBillId(rss.getInt("bill_id"));
				FillBillAction.billLines[startingPoint].getAmountTextField().setText(rss.getString("bill_amount"));
				//billLines.getAmountTextField().setText("999");
				FillBillAction.billLines[startingPoint].getSumTextField().setText(rss.getString("bill_cost"));
				FillBillAction.billLines[startingPoint].setProductId(rss.getInt("product_id"));
				FillBillAction.billLines[startingPoint].setSpecialPrice(rss.getFloat("special_price"));
				FillBillAction.billLines[startingPoint].getPriceTextField().setText(
				Float.toString((FillBillAction.billLines[startingPoint].getSpecialPrice())));
				
				
					
					
					for(int n=0;n<customers.length;n++){
						////////////System.out.println("wanted cCode="+rss.getString("customer_code")+"   cCode= "+customers[n].getCustomerCode());
						if(rss.getString("customer_code").equals(customers[n].getCustomerCode())){
							customerIndex=n;
							//////////////System.out.println("customerName!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!="+customers[customerIndex].getCustomerName());
						}
					}
					
					// I find promtionIndex here
					
					for(int n=0;n<promotions.length;n++){
						
						////////System.out.println("wanted pId="+rss.getString("product_id")+"   pid= "+promotions[n].getPromotionProductId());
						////////System.out.println("wanted cId="+customers[customerIndex].getCustomerId()+"   pmCid= "+promotions[n].getPromotionCustomerId());
						if(rss.getInt("product_id")==promotions[n].getPromotionProductId() && customers[customerIndex].getCustomerId()==promotions[n].getPromotionCustomerId()){
							////////System.out.println("promotion found!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
							promotionIndex=n;
							////////System.out.println("promotion index="+promotionIndex);
						}
						
					}
					
					
					
					
					if(promotionIndex>-1){
						FillBillAction.billLines[startingPoint].getPromotionTextField().getDocument().removeDocumentListener(FillBillAction.promotionDocumentListener);
						FillBillAction.billLines[startingPoint].getPromotionTextField().setText(Integer.toString(rss.getInt("promotion_amount")));
						FillBillAction.billLines[startingPoint].setBillPromotionAmount(rss.getInt("promotion_amount"));
						FillBillAction.billLines[startingPoint].setBillModifyingPromotionAmount(0);
						FillBillAction.billLines[startingPoint].getPromotionTextField().getDocument().addDocumentListener(FillBillAction.promotionDocumentListener);					
						FillBillAction.billLines[startingPoint].getTotalPromotionTextField().setText(Integer.toString(promotions[promotionIndex].getPromotionUnit()));
					/*	//////System.out.println("");
						//////System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
						//////System.out.println("");
						//////System.out.println("bill Promotion Unit="+Integer.toString(promotions[promotionIndex].getPromotionUnit()));
						//////System.out.println("");
						//////System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
						//////System.out.println("");*/
						FillBillAction.billLines[startingPoint].setBillPromotionUnit(promotions[promotionIndex].getPromotionUnit());
						FillBillAction.billLines[startingPoint].setBillModifyingPromotionUnit(promotions[promotionIndex].getPromotionUnit());
						//////////System.out.println("billineId="+startingPoint);
					//FillBillAction.billLines[startingPoint].getPromotionTextField().getDocument().addDocumentListener(FillBillAction.promotionDocumentListener);
						FillBillAction.Calculate(FillBillAction.tempRowCounter);
					
					}
					
					
					FillBillAction.billLines[startingPoint].getCashCheckBox().setEnabled(true);
					FillBillAction.billLines[startingPoint].getCreditCheckBox().setEnabled(true);;
					FillBillAction.billLines[startingPoint].getCreditCashTextField().setEnabled(true);	
					
					
					
				
				//FillBillAction.billLines[startingPoint].getCashCheckBox().setSelected(true);
				
					FillBillAction.billLines[startingPoint].setBillTotalCost(rss.getFloat("bill_cost"));
				//System.out.println("totalCost="+FillBillAction.billLines[startingPoint].getBillTotalCost());
				
				if(rss.getFloat("bill_credit")==rss.getFloat("bill_cost")){
					
					//////System.out.println("payed by credit");
					
					FillBillAction.billLines[startingPoint].getCreditCheckBox().setSelected(true);
					FillBillAction.billLines[startingPoint].getCreditCheckBox().doClick();
					FillBillAction.billLines[startingPoint].getCreditCheckBox().setSelected(true);
					FillBillAction.billLines[startingPoint].setBillCredit(rss.getFloat("bill_credit"));
					FillBillAction.billLines[startingPoint].setPayedCash(0);
					//////////System.out.println("credit="+FillBillAction.billLines[startingPoint].getBillCredit());
					FillBillAction.billLines[startingPoint].setCreditCashTextFieldStatus(true);
					FillBillAction.billLines[startingPoint].setCashCheckBoxStatus(false);
					FillBillAction.billLines[startingPoint].setCreditCashTextFieldStatus(false);
					/*FillBillAction.billLines[startingPoint].getCreditCheckBox().setEnabled(true);
					FillBillAction.billLines[startingPoint].getCashCheckBox().setEnabled(false);
					FillBillAction.billLines[startingPoint].getCreditCashTextField().setEnabled(false);*/
				}
				else if(rss.getFloat("bill_cash")==rss.getFloat("bill_cost")){
					
					////////System.out.println("payed by cash");
					
					FillBillAction.billLines[startingPoint].getCashCheckBox().setSelected(true);
					FillBillAction.billLines[startingPoint].setBillCash(rss.getFloat("bill_cash"));
					FillBillAction.billLines[startingPoint].setPayedCash(rss.getFloat("bill_cash"));
					//////////System.out.println("cash="+FillBillAction.billLines[startingPoint].getBillCash());
					FillBillAction.billLines[startingPoint].setCreditCashTextFieldStatus(false);
					FillBillAction.billLines[startingPoint].setCashCheckBoxStatus(true);
					FillBillAction.billLines[startingPoint].setCreditCashTextFieldStatus(false);
					/*FillBillAction.billLines[startingPoint].getCashCheckBox().setEnabled(true);
					FillBillAction.billLines[startingPoint].getCreditCheckBox().setEnabled(false);
					FillBillAction.billLines[startingPoint].getCreditCashTextField().setEnabled(false);*/
				}
				else{
					//////System.out.println("payed by creditcash");
				
					
					if(rss.getFloat("bill_cash")!=rss.getFloat("bill_cost") && rss.getFloat("bill_credit")!=rss.getFloat("bill_cost") ){
						FillBillAction.billLines[startingPoint].getCreditCashTextField().setText(Float.toString(rss.getFloat("bill_cash")));
						
					}
					FillBillAction.billLines[startingPoint].setBillCredit(rss.getFloat("bill_credit"));
					//////////System.out.println("remain="+FillBillAction.billLines[startingPoint].getBillCredit());
					FillBillAction.billLines[startingPoint].setBillCash(rss.getFloat("bill_cash"));
					//////////System.out.println("credit="+FillBillAction.billLines[startingPoint].getBillCredit());
					FillBillAction.billLines[startingPoint].setPayedCash(rss.getFloat("bill_cash"));
					FillBillAction.billLines[startingPoint].setCreditCashTextFieldStatus(false);
					FillBillAction.billLines[startingPoint].setCashCheckBoxStatus(false);
					FillBillAction.billLines[startingPoint].setCreditCashTextFieldStatus(true);
					/*FillBillAction.billLines[startingPoint].getCashCheckBox().setEnabled(false);
					FillBillAction.billLines[startingPoint].getCreditCheckBox().setEnabled(false);
					FillBillAction.billLines[startingPoint].getCreditCashTextField().setEnabled(true);*/
				}
				
				/*FillBillAction.billLines[startingPoint].getCreditCashTextField().setEditable(false);
				FillBillAction.billLines[startingPoint].getCreditCashTextField().removeMouseListener(FillBillAction.CustomMouseListener);
				FillBillAction.billLines[startingPoint].getCashCheckBox().setEnabled(false);
				FillBillAction.billLines[startingPoint].getCreditCheckBox().setEnabled(false);*/
             	
				FillBillAction.billLines[startingPoint].getCreditCashTextField().setEditable(true);
             	//FillBillAction.billLines[FillBillAction.selectedRadioButton].getCreditCashTextField().addMouseListener(FillBillAction.CustomMouseListener);
				FillBillAction.billLines[startingPoint].getCashCheckBox().setEnabled(true);
				FillBillAction.billLines[startingPoint].getCreditCheckBox().setEnabled(true);
				
				
             	FillBillAction.CalculateTotalCostOfLine();
				// I find customerIndex here
				FillBillAction.Calculate(FillBillAction.tempRowCounter);
				
				startingPoint++;
				counter++;
			}
			
			for(int g=startingPoint;g<howMany-(startingPoint-firstStartingPoint);g++){
				FillBillAction.billLines[g].getBillProductComboBox().setSelectedIndex(0);
			}
				
			}
			else if(recordCounter==0){
				FillBillAction.CalculateTotalCostOfLine();
				FillBillAction.Calculate(FillBillAction.tempRowCounter);
				//////////System.out.println("recordCounter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!="+recordCounter);
				
				for(int g=firstStartingPoint;g<howMany;g++){
					FillBillAction.billLines[g].getBillProductComboBox().setSelectedIndex(0);
				}
				/*FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().setEditable(false);
				FillBillAction.billLines[billLine.getbillLineid()].getCreditCashTextField().removeMouseListener(FillBillAction.CustomMouseListener);
				FillBillAction.billLines[billLine.getbillLineid()].getCashCheckBox().setEnabled(false);
				FillBillAction.billLines[billLine.getbillLineid()].getCreditCheckBox().setEnabled(false);
             	
				if(billLine.getbillLineid()!=FillBillAction.selectedRadioButton){
					FillBillAction.billLines[FillBillAction.selectedRadioButton].getCreditCashTextField().setEditable(true);
					FillBillAction.billLines[FillBillAction.selectedRadioButton].getCreditCashTextField().addMouseListener(FillBillAction.CustomMouseListener);
					FillBillAction.billLines[FillBillAction.selectedRadioButton].getCashCheckBox().setEnabled(true);
					FillBillAction.billLines[FillBillAction.selectedRadioButton].getCreditCheckBox().setEnabled(true);
				}*/
			}
			
			
			
			
			
			 conn.close();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
       
       
		
		return null;
		
		
		
	}
	
	
	

	private static int controlForDuplicate(ResultSet rss) throws SQLException {
		
		//////System.out.println("in control for duplicate");
		
		for(int counter=0;counter<BillAdditionMenu.rowCounter;counter++){
			if(rss.getString("customer_code").equals(FillBillAction.billLines[counter].getCustomerCode())
					&& rss.getInt("product_id")==FillBillAction.billLines[counter].getProductId()){
				//////System.out.println("duplicate detected!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
				duplicateCounter++;
			}
			
		}
		
		////////System.out.println("duplicatecounter="+duplicateCounter);
		return duplicateCounter;
	}

}
